package dnl.utils.mail;

import java.io.Serializable;

import org.jasypt.util.text.BasicTextEncryptor;

/**
 * 
 * @author Daniel Orr
 * 
 */
public class MailAccount implements Serializable {

	private static final String ENCRYPTOR_PASSWORD = "D5a4n3i2e1l";

	private String name;

	private String hostName;

	private String user;

	private String sendAddress;
	
	private String passwordImpl;

	private String smtpPort;

	private EncryptionType encriptionType;

	private BasicTextEncryptor encryptor;

	public MailAccount() {
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getHostName() {
		return hostName;
	}

	public void setHostName(String hostName) {
		this.hostName = hostName;
	}

	public String getUser() {
		return user;
	}

	public void setUser(String user) {
		this.user = user;
	}

	public String getPassword() {
		return getEncryptor().decrypt(this.passwordImpl);
	}

	public void setPassword(String password) {
		this.passwordImpl = getEncryptor().encrypt(password);
	}

	public String getPasswordImpl() {
		return passwordImpl;
	}

	public void setPasswordImpl(String password) {
		this.passwordImpl = password;
	}

	public String getSendAddress() {
		return sendAddress;
	}

	public void setSendAddress(String sendAddress) {
		this.sendAddress = sendAddress;
	}

	public String getSmtpPort() {
		return smtpPort;
	}

	public void setSmtpPort(String smtpPort) {
		this.smtpPort = smtpPort;
	}

	public EncryptionType getEncriptionType() {
		return encriptionType;
	}

	public void setEncriptionType(EncryptionType encriptionType) {
		this.encriptionType = encriptionType;
	}

	private BasicTextEncryptor getEncryptor(){
		if(encryptor == null){
			encryptor = new BasicTextEncryptor();
			encryptor.setPassword(ENCRYPTOR_PASSWORD);			
		}
		return encryptor;
	}
}
